//
//  DateConflictView.m
//  MobileOffice
//
//  Created by jjkj on 16/11/9.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "DateConflictView.h"

@implementation DateConflictView
- (instancetype)initWithFrame:(CGRect)frame message:(NSString *)message{
    if (self=[super initWithFrame:frame]) {
        self.backgroundColor=[UIColor clearColor];
        _buttonArr=[NSMutableArray new];
        
        UIView *backView=[[UIView alloc]initWithFrame:frame];
        backView.backgroundColor=[UIColor blackColor];
        backView.alpha=0.4;
        [self addSubview:backView];
        
        UIView *contentView=[[UIView alloc]initWithFrame:CGRectMake(50, 200, IPHONE_WIDTH-2*50, 150)];
        contentView.backgroundColor=[UIColor whiteColor];
        contentView.layer.masksToBounds=YES;
        contentView.layer.cornerRadius=8;
        [self addSubview:contentView];
        

        
        //内容信息
        _messageLabel=[MyControl creatLabelWithFrame:CGRectMake(10, 10, contentView.width-20, 20) text:message];
        _messageLabel.textColor=[UIColor blackColor];
        _messageLabel.numberOfLines=0;
        _messageLabel.font=[UIFont boldSystemFontOfSize:16];;
        _messageLabel.textAlignment=NSTextAlignmentCenter;
        [contentView addSubview:_messageLabel];
        CGFloat messageHeight=[LZXHelper textHeightFromTextString:message width:_messageLabel.width fontSize:16]+3;
        [_messageLabel changeView_Height:messageHeight];
        
        UILabel *line1=[MyControl creatLabelWithFrame:CGRectMake(0, _messageLabel.y+_messageLabel.height+8, contentView.width, 1) text:@""];
        line1.backgroundColor=BACKCOLOR_GRAY;
        [contentView addSubview:line1];
        
        NSArray *title1=@[@"重新选择时间",@"结束之前申请",@"撤销之前申请",@"顺延之前申请"];
        for (int i=0; i<title1.count; i++) {
            UIButton *button=[MyControl creatButtonWithFrame:CGRectMake(0,line1.y+line1.height+8+40*i, contentView.width, 40) target:self sel:@selector(selectButton:) tag:130+i image:nil title:title1[i]];
            button.layer.masksToBounds=YES;
            button.layer.cornerRadius=5;
            button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"k_ic_rb1@2x"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"k_ic_rb2@2x"] forState:UIControlStateSelected];
            button.imageEdgeInsets=UIEdgeInsetsMake(7, button.width-36, 7, 20);
            //button.titleEdgeInsets=UIEdgeInsetsMake(10, 10, 10, 40);
            [_buttonArr addObject:button];
            if (i==0) {
                button.selected=YES;
            }
            [contentView addSubview:button];
        }
        
        UILabel *line2=[MyControl creatLabelWithFrame:CGRectMake(0, line1.y+line1.height+8+40*title1.count+8, contentView.width, 1) text:@""];
        line2.backgroundColor=BACKCOLOR_GRAY;
        [contentView addSubview:line2];
        
        NSArray *title2=@[@"确认",@"取消"];
        CGFloat buttonWidth2=(contentView.width-2*120)/3;
        for (int i=0; i<title2.count; i++) {
            _submitButton=[MyControl creatButtonWithFrame:CGRectMake(buttonWidth2*(i+1)+120*i,line2.y+line2.height+10, 120, 40) target:self sel:@selector(submitClick:) tag:120+i image:nil title:title2[i]];
            _submitButton.layer.masksToBounds=YES;
            _submitButton.layer.cornerRadius=5;
            [_submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            if (i==0) {
                _submitButton.backgroundColor=COLOR_MIDBLUE;
            }else{
                _submitButton.backgroundColor=[UIColor orangeColor];
            }
            [contentView addSubview:_submitButton];
        }
        [contentView changeView_Height:_submitButton.y+_submitButton.height+15];
        [contentView changeView_Y:(IPHONE_HEIGHT-(_submitButton.y+_submitButton.height+8))/2];
        //        _lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 49, IPHONE_WIDTH, 1)];
        //        _lineLabel.backgroundColor=BACKCOLOR_GRAY;
        //        [self.contentView addSubview:_lineLabel];
    }
    return self;
}

- (void)submitClick:(UIButton *)button{
    if (button.tag==120) {
        [self removeFromSuperview];
        if (_promptTimeBlock) {
            for (int i=0; i<_buttonArr.count; i++) {
                if (i!=0) {
                    UIButton *newButton=_buttonArr[i];
                    if (newButton.selected) {
                        _promptTimeBlock([_buttonArr indexOfObject:newButton]);
                        break;
                    }
                }
            }

        }
    }else{
        [self removeFromSuperview];
        if (_promptTimeCancelBlock) {
            _promptTimeCancelBlock();
        }
    }
}

- (void)selectButton:(UIButton *)button{
    for (int i=0; i<_buttonArr.count; i++) {
        UIButton *newButton=_buttonArr[i];
        if (button.tag==newButton.tag) {
            newButton.selected=YES;
        }else{
            newButton.selected=NO;
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
